import { APlugin } from '../types/common.interface';
import { Injectable, PluginInjectable } from '../decorators/inject';
import { Select } from '../cors/select';
import { ExecuteRecord } from '../cors/execute-record';
import { Config } from '../cors/config';
import './row-height.plugin.less';
import { RenderTrigger } from '../cors/render-trigger';
import { HiddenRowCommand } from '../commands/hidden-row-command';
import { HiddenColCommand } from '../commands/hidden-col-command';

@Injectable()
@PluginInjectable('HiddenRowColPlugin')
export class HiddenRowColPlugin extends APlugin {
    constructor(
        protected conf: Config,
        protected render: RenderTrigger,
        protected select: Select,
        protected executeRecord: ExecuteRecord,
    ) {
        super();
    }
    public init() {

    }
    public hiddenRows() {
        let selected = this.select.selected;
        let rows: number[] = [];
        for(let row = selected.row; row < selected.row + selected.rowspan; row++) {
            rows.push(row);
        }
        if(rows.length === 0) {
            console.warn('no rows');
            return;
        }
        let command = new HiddenRowCommand(this.conf, this.render, rows, 'add');
        this.executeRecord.execute(command);
        this.render.triggerRenderAll();
    }
    public cancelHiddenRows() {
        let selected = this.select.selected;
        let rows: number[] = [];
        for(let row = selected.row; row < selected.row + selected.rowspan; row++) {
            rows.push(row);
        }
        if(rows.length === 0) {
            console.warn('no rows');
            return;
        }
        let command = new HiddenRowCommand(this.conf, this.render, rows, 'remove');
        this.executeRecord.execute(command);
        this.render.triggerRenderAll();
    }
    public hiddenCols() {
        let selected = this.select.selected;
        let cols: number[] = [];
        for(let col = selected.col; col < selected.col + selected.colspan; col++) {
            cols.push(col);
        }
        if(cols.length === 0) {
            console.warn('no cols');
            return;
        }
        let command = new HiddenColCommand(this.conf, this.render, this.select, cols, 'add');
        this.executeRecord.execute(command);
        this.render.triggerRenderAll();
    }
    public cancelHiddenCols() {
        let selected = this.select.selected;
        let cols: number[] = [];
        for(let col = selected.col; col < selected.col + selected.colspan; col++) {
            cols.push(col);
        }
        if(cols.length === 0) {
            console.warn('no cols');
            return;
        }
        let command = new HiddenColCommand(this.conf, this.render, this.select, cols, 'remove');
        this.executeRecord.execute(command);
        this.render.triggerRenderAll();
    }
    public getSelectInfo() {
        return this.select.selected;
    }
    public getHiddenRows() {
        return Array.from(this.conf.hiddenRows);
    }
    public getHiddenCols() {
        return Array.from(this.conf.hiddenCols);
    }
    public destroy() {
        
    }
}